package com.glb.gilibuy.service.impl;

import com.glb.gilibuy.dao.OrderCommentDao;
import com.glb.gilibuy.entity.CyclePic;
import com.glb.gilibuy.entity.OrderComment;
import com.glb.gilibuy.entity.OrderCommentExample;
import com.glb.gilibuy.service.OrderCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: Yingtian qian
 * @Date: 2021/8/5 9:22
 */
@Service
public class OrderCommentServiceImpl implements OrderCommentService {
    @Autowired
    private OrderCommentDao orderCommentDao;

    @Override
    public OrderComment selectCommentByConmmentId(String commentId) {
        if (!"".equals(commentId)) {
            OrderCommentExample orderCommentExample = new OrderCommentExample();
            orderCommentExample.or().andCommentContentEqualTo(commentId).andIsDeletedEqualTo(0);
            List<OrderComment> orderCommentList = orderCommentDao.selectByExample(orderCommentExample);
            if (orderCommentList.isEmpty()) {
                return null;
            }
            return orderCommentList.get(0);
        }
        return null;
    }

    @Override
    public List<OrderComment> selectCommentsByProductId(String productId) {
        if (!"".equals(productId)) {
            OrderCommentExample orderCommentExample = new OrderCommentExample();
            orderCommentExample.setOrderByClause("id desc");
            orderCommentExample.or().andProductIdEqualTo(productId).andIsDeletedEqualTo(0);
            List<OrderComment> orderCommentList = orderCommentDao.selectByExample(orderCommentExample);
            return orderCommentList;
        }
        return null;
    }

}
